package com.ruoyi.web.controller.qsng;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.qsng.domain.KCourseType;
import com.ruoyi.qsng.service.IKCourseTypeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 课程分类Controller
 *
 * @author kanglou
 * @date 2023-06-07
 */
@RestController
@RequestMapping("/qsng/courseType")
@Api(tags = "pc--课程分类Controller")
public class KCourseTypeController extends BaseController {
    @Autowired
    private IKCourseTypeService kCourseTypeService;

    /**
     * 查询课程分类列表
     */
    @PreAuthorize("@ss.hasPermi('qsng:courseType:list')")
    @GetMapping("/list")
    @ApiOperation(value = "查询课程分类列表")
    public TableDataInfo list(KCourseType kCourseType) {
        startPage();
        List<KCourseType> list = kCourseTypeService.selectKCourseTypeList(kCourseType);
        return getDataTable(list);
    }

    /**
     * 查询课程分类列表
     */
    @PreAuthorize("@ss.hasPermi('qsng:courseType:list')")
    @GetMapping("/listNotLimit")
    @ApiOperation(value = "查询课程分类列表")
    public AjaxResult listNotLimit(KCourseType kCourseType) {
        List<KCourseType> list = kCourseTypeService.selectKCourseTypeList(kCourseType);
        return success(list);
    }

    /**
     * 导出课程分类列表
     */
    @PreAuthorize("@ss.hasPermi('qsng:courseType:export')")
    @Log(title = "课程分类", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ApiOperation(value = "导出课程分类列表")
    public void export(HttpServletResponse response, KCourseType kCourseType) {
        List<KCourseType> list = kCourseTypeService.selectKCourseTypeList(kCourseType);
        ExcelUtil<KCourseType> util = new ExcelUtil<KCourseType>(KCourseType.class);
        util.exportExcel(response, list, "课程分类数据");
    }

    /**
     * 获取课程分类详细信息
     */
    @PreAuthorize("@ss.hasPermi('qsng:courseType:query')")
    @GetMapping(value = "/{id}")
    @ApiOperation(value = "获取课程分类详细信息")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return success(kCourseTypeService.selectKCourseTypeById(id));
    }

    /**
     * 新增课程分类
     */
    @PreAuthorize("@ss.hasPermi('qsng:courseType:add')")
    @Log(title = "课程分类", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation(value = "新增课程分类")
    public AjaxResult add(@RequestBody KCourseType kCourseType) {
        return toAjax(kCourseTypeService.insertKCourseType(kCourseType));
    }

    /**
     * 修改课程分类
     */
    @PreAuthorize("@ss.hasPermi('qsng:courseType:edit')")
    @Log(title = "课程分类", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation(value = "修改课程分类")
    public AjaxResult edit(@RequestBody KCourseType kCourseType) {
        return toAjax(kCourseTypeService.updateKCourseType(kCourseType));
    }

    /**
     * 删除课程分类
     */
    @PreAuthorize("@ss.hasPermi('qsng:courseType:remove')")
    @Log(title = "课程分类", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    @ApiOperation(value = "删除课程分类")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(kCourseTypeService.deleteKCourseTypeByIds(ids));
    }
}
